/**
 * 
 */
package br.edu.ufcg.embedded.mysocial;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;

import br.embedded.socialapp.business.Coordenates;
import br.embedded.socialapp.business.CoordenatesComparator;

/**
 * @author daniel
 *
 */
public class CoordinatesGenerator
{
	public static List<List<Coordenates>> generateCoordinates(double lat1, double long1, double lat2,
			double long2, double maxDistance, double factor, int count)
	{
		List<List<Coordenates>> coordenatesList = new ArrayList<List<Coordenates>>(2);
		
		coordenatesList.add(0, new ArrayList<Coordenates>());
		coordenatesList.add(1, new ArrayList<Coordenates>());
		
		  Coordenates c1 = new Coordenates();
		  c1.setLatitude(lat1);
		  c1.setLongitude(long1);
		  
		  double latitude = lat2;
		  double distance = 0.0;
		  
		  for (int i = 0; i < count; i++)
		  {
			  latitude -= factor;
			  Coordenates c2 = new Coordenates();
			  c2.setLatitude(latitude);
			  c2.setLongitude(long1);
		  
			  distance = LocationHandler.calculateDistance(c1, c2);
			  c2.setDistance(distance);
			  
			  if (distance < maxDistance)
				  coordenatesList.get(0).add(c2);
			  else
				  coordenatesList.get(1).add(c2);
		  }
		  
		  double longitude = long2;
		  distance = 0.0;
		  
		  for (int i = 0; i < count; i++)
		  {
			  longitude += factor;
			  Coordenates c2 = new Coordenates();
			  c2.setLatitude(lat1);
			  c2.setLongitude(longitude);
		  
			  distance = LocationHandler.calculateDistance(c1, c2);
			  c2.setDistance(distance);
			  
			  if (distance < maxDistance)
				  coordenatesList.get(0).add(c2);
			  else
				  coordenatesList.get(1).add(c2);
		  }
		  
		  Collections.sort(coordenatesList.get(0), new CoordenatesComparator());
		  Collections.sort(coordenatesList.get(1), new CoordenatesComparator());
		  
		  return coordenatesList;
	}
	
	public static int getCoordinate(List<Coordenates> coordenates)
	{
		Random random = new Random();
		return random.nextInt(coordenates.size());
	}
}
